import utils from "../common/util.js"

export default {

	// 获取自选基金列表
	getList(){
		return new Promise((resolve, reject) => {
			uni.request({
				url: utils.basicUrl+'/zixuan',
				method: 'GET',
				data:{
				},
				success: function(res) {
					if(res.data.code === 20000){
						resolve(res.data.data)
					}else{
						utils.requestFail(res)
					}
				},
				fail: () => {
					uni.showModal({
						content: '网络错误',
						showCancel: false
					});
				}
			})
		})
	},
	
	// 添加自选基金
	add(zixuan){
		return new Promise((resolve, reject) => {
			uni.request({
				url: utils.basicUrl+'/zixuan',
				method: 'POST',
				data:{
					...zixuan
				},
				success: function(res) {
					if(res.data.code === 20000){
						resolve("ok")
					}else{
						utils.requestFail(res)
					}
				},
				fail: () => {
					uni.showModal({
						content: '网络错误',
						showCancel: false
					});
				}
			})
		})
	},
	
	// 删除自选基金
	deleteByIds(ids){
		return new Promise((resolve, reject) => {
			uni.request({
				url: utils.basicUrl+'/zixuan/ids',
				method: 'DELETE',
				data: JSON.stringify(ids),
				success: function(res) {
					if(res.data.code === 20000){
						resolve("ok")
					}else{
						utils.requestFail(res)
					}
				},
				fail: () => {
					uni.showModal({
						content: '网络错误',
						showCancel: false
					});
				}
			})
		})
	}
		
}